/*
 * Copyright (C) 2010-2010 MaoJian Wu
 *
 * Author:
 *	MaoJian Wu
 *
 * Source:
 *	
 *
 * This file is a part of zfspear library.
 *
 *
 */

#include <QtTest/QtTest>
#include "test_xmpp_stream_parser.h"

#include "xmpp_stream_parser.h"
#include "xmpp_element.h"
#include "stream_element.h"
#include "Jid.h"
#include "xmpp_element_factory.h"
TestXmppStreamParser::TestXmppStreamParser(QObject *parent) :
    QObject(parent),xmppStreamParser_()
{
   XmppElementFactory a;
   this->connect(&xmppStreamParser_,SIGNAL(OnStreamElement(XmppElement *)),SLOT(OnStreamElement(XmppElement *)));
   this->connect(&xmppStreamParser_,SIGNAL(OnStreamStart(XmppElement *)),SLOT(OnStreamStart(XmppElement *)));
   this->connect(&xmppStreamParser_,SIGNAL(OnStreamEnd(XmppElement *)),SLOT(OnStreamEnd(XmppElement *)));
}
void TestXmppStreamParser::toDoTtlTest() {

     QString  xml="<stream:features>" \
                  "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'>" \
                    "<required/>" \
                  "</starttls>" \
                  "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" \
                    "<mechanism>DIGEST-MD5</mechanism>" \
                    "<mechanism>PLAIN</mechanism>" \
                  "</mechanisms>" \
                "</stream:features>";

   
   QByteArray byte = xml.toAscii();
   xmppStreamParser_.Parser(byte);


}


void TestXmppStreamParser::toDoParserTest() {

   
   QString xml="<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='node1@domain1' to='node2@domain2' id='streamid1237' version='1.0' xml:lang='en'  xmlns:xml='http://www.w3.org/XML/1998/namespace'>";
   
   QByteArray byte = xml.toAscii();
   // xmppStreamParser_.Parser(byte);


}
void TestXmppStreamParser::OnStreamElement(XmppElement *xmppElement) {

    QVERIFY(xmppElement!=NULL);
    //QCOMPARE(QString("Features"),xmppElement->metaObject()->className());
    QVERIFY(xmppElement->HaveTag("starttls"));
	QString  xml="<stream:features>" \
                  "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'>" \
                    "<required/>" \
                  "</starttls>" \
                  "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" \
                    "<mechanism>DIGEST-MD5</mechanism>" \
                    "<mechanism>PLAIN</mechanism>" \
                  "</mechanisms>" \
                "</stream:features>";
    //QCOMPARE(xml,xmppElement->ToString());
    QString className(xmppElement->metaObject()->className());
    if (className == "Features") {
		QString aa=xmppElement->ToString();
        if (xmppElement->HaveTag("starttls")) {
            QString a="";
        }
    }
}

void TestXmppStreamParser::OnStreamStart(XmppElement *xmppElement) {

    QVERIFY(xmppElement!=NULL);

	
    QVERIFY(qobject_cast<StreamElement *>(xmppElement)!=NULL);
    StreamElement *streamElement=qobject_cast<StreamElement *>(xmppElement);
	
    QCOMPARE(QString("stream"),streamElement->TagName());
    QCOMPARE(QString("stream"),streamElement->Prefix());

	QString a= streamElement->Xmllang();
    QCOMPARE(QString("en"),streamElement->Xmllang());

    //QCOMPARE(QString("node1@domain1"),streamElement->From()->ToString());
    //QCOMPARE(QString("node2@domain2"),streamElement->To()->ToString());
    QCOMPARE(QString("1.0"),streamElement->Version());
    QCOMPARE(QString("http://etherx.jabber.org/streams"),streamElement->Xmlns());
	
}
void TestXmppStreamParser::OnStreamEnd(XmppElement *xmppElement) {
    QVERIFY(xmppElement!=NULL);
    /*QVERIFY(qobject_cast<StreamElement *>(xmppElement)!=NULL);
    StreamElement *streamElement=dynamic_cast<StreamElement *>(xmppElement);
    QCOMPARE("stream",streamElement->TagName());
    QCOMPARE("stream",streamElement->Prefix());
    QCOMPARE("en",streamElement->Xmllang());
    QCOMPARE("node1@domain1",streamElement->From()->ToString());
    QCOMPARE("node2@domain2",streamElement->To()->ToString());
    QCOMPARE("1.0",streamElement->Version());
    QCOMPARE("http://etherx.jabber.org/streams",streamElement->Xmlns());*/
}

